#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QTimer>
#include <QKeyEvent>
#include <QMovie>
#include <QLabel>
#include <QThread>
#include <QUdpSocket>
#ifdef __linux
#include <linux/input.h>
#endif
#include <fcntl.h>
#include <unistd.h>

#include <QWSServer>
#include <QWSWindow>

#include "../remoteservice/devicestatusinfo.h"
#include "../remoteservice/platfromstatusinfo.h"
#include "../remoteservice/productinfo.h"
#include "../remoteservice/networkinfo.h"
#include "../remoteservice/svcstatusinfo.h"

namespace Ui {
    class MainWindow;
}

typedef struct Stats {
    QString direct;
    QString protocol;
    QString callrate;
    QString resolution;
    QString fps;
    QString lose_packet;
    QString safe;
} StatsItem;

class WaitingPage;
class MeetControlPage;
class CallControlPanel;
class KeyBoard;
class QPropertyAnimation;
class PasswordInput;
class MessageDialog;
class MainWindowWorker;
class BaseSettingPage;
class IndexPage;

class WorkThread;
class MainWindow : public QMainWindow {
    Q_OBJECT

signals:

    void updateStatus();

private:
    void init();

private slots:
    void changeTopPageSlot(int);
    void changeSubPageSlot(int);
    void showKeyBoard(QObject *,int);
    void hideKeyBoard();
    void showMsg(QString str);
    void showPwdInput(QString num, QString name);

    void deviceInfoSlot(DeviceStatusInfo);
    void platformInfoSlot(PlatfromStatusInfo);
    void productInfoSlot(ProductInfo);
    void networkInfoSlot(NetworkInfo);
    void svcInfoSlot(SVCStatusInfo info);

    void updateDeviceName(QString);
    void updateIP(QString);
    void updateNetStatus(bool active);
    void updateRegistered(int v);
    void updateDeviceStatus(int v);
    void updateSVCRegistered(int v);

    void leaveConf();
    void enterConf();
    void exitApp();

    void backgroundProperty(QString value);

protected:
	void paintEvent(QPaintEvent *);
	bool eventFilter(QObject *, QEvent *);
    void showEvent(QShowEvent *e);
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    void loadSchedule();

private slots:
    void timerHandle();

private:
    Ui::MainWindow *ui;

    QTimer m_timer;

    int m_second_count;     //记录次数，当时钟走过一定的秒数，就进行更新页面状态

    WaitingPage *m_waitpage;
    MeetControlPage *m_meetpage;
    KeyBoard *m_keyboard;
    QPropertyAnimation *m_keyboardAnimation;
    PasswordInput *m_pwdpage;
    MessageDialog *m_msgpage;
    BaseSettingPage *m_basepage;
    IndexPage *m_indexpage;

    MainWindowWorker *worker;
    QThread workThread;
    int curState;       //0：待机状态；1：运行状态
};

#endif // MAINWINDOW_H

